﻿//////////////////////////////////////////////////////////////////
//
// TestCharles\AlmanacLocation.cs
//
// Copyright (c) 2012 Dan Pike.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation files
// (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using Almanac;
using Interfaces;
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Utilities;

namespace TestCharles
{
   [TestClass]
   public class AlmanacLocation
   {
      private Logger logger_;

      public AlmanacLocation()
      {
         logger_ = new Logger();
      }

      [TestMethod]
      public void TestEmptyLocation()
      {
         Location location = new Location();
         Assert.AreEqual(0, location.Longitude);
         Assert.AreEqual(0, location.LongitudeTotalMinutes);
         Assert.AreEqual(Hemisphere.None, location.LongitudeHemisphere);
         Assert.AreEqual(0, location.LongitudeDegrees);
         Assert.AreEqual(0, location.LongitudeMinutes);
         Assert.AreEqual(0, location.LongitudeSeconds);
         Assert.AreEqual(0, location.Latitude);
         Assert.AreEqual(0, location.LatitudeTotalMinutes);
         Assert.AreEqual(Hemisphere.None, location.LatitudeHemisphere);
         Assert.AreEqual(0, location.LatitudeDegrees);
         Assert.AreEqual(0, location.LatitudeMinutes);
         Assert.AreEqual(0, location.LatitudeSeconds);
         Assert.AreEqual(0, location.Altitude);
         Assert.AreEqual(location, new Location());
         Assert.AreNotSame(location, new Location());
      }

      [TestMethod]
      public void TestCopyFrom()
      {
         ILocation location = new Location();
         location.Altitude = 1234;
         location.LongitudeHemisphere = Hemisphere.West;
         location.LongitudeDegrees = 147;
         location.LongitudeMinutes = 47;
         location.LongitudeSeconds = 7;
         location.LatitudeHemisphere = Hemisphere.South;
         location.LatitudeDegrees = 46;
         location.LatitudeMinutes = 6;
         location.LatitudeSeconds = 0.6f;
         ILocation copy = new Location().CopyFrom(location);
         Assert.AreNotSame(location, copy);
         Assert.AreEqual(location, copy);
      }

      [TestMethod]
      public void TestMoveEast()
      {
         Location location = new Location();
         location.Move(0, 4000.0f);
         Assert.AreEqual(4000, location.Longitude);
         Assert.AreEqual(66, location.LongitudeTotalMinutes);
         Assert.AreEqual(Hemisphere.East, location.LongitudeHemisphere);
         Assert.AreEqual(1, location.LongitudeDegrees);
         Assert.AreEqual(6, location.LongitudeMinutes);
         Assert.AreEqual(40, location.LongitudeSeconds);
         Assert.AreEqual(0, location.Latitude);
         Assert.AreEqual(0, location.LatitudeTotalMinutes);
         Assert.AreEqual(Hemisphere.North, location.LatitudeHemisphere);
         Assert.AreEqual(0, location.LatitudeDegrees);
         Assert.AreEqual(0, location.LatitudeMinutes);
         Assert.AreEqual(0, location.LatitudeSeconds);
         Assert.AreEqual(0, location.Altitude);
         Assert.AreNotEqual(location, new Location());
         Assert.AreNotSame(location, new Location());
      }

      [TestMethod]
      public void TestMoveWest()
      {
         Location location = new Location();
         location.Move(0, -4000.0f);
         Assert.AreEqual(-4000, location.Longitude);
         Assert.AreEqual(-66, location.LongitudeTotalMinutes);
         Assert.AreEqual(Hemisphere.West, location.LongitudeHemisphere);
         Assert.AreEqual(1, location.LongitudeDegrees);
         Assert.AreEqual(6, location.LongitudeMinutes);
         Assert.AreEqual(40, location.LongitudeSeconds);
         Assert.AreEqual(0, location.Latitude);
         Assert.AreEqual(0, location.LatitudeTotalMinutes);
         Assert.AreEqual(Hemisphere.North, location.LatitudeHemisphere);
         Assert.AreEqual(0, location.LatitudeDegrees);
         Assert.AreEqual(0, location.LatitudeMinutes);
         Assert.AreEqual(0, location.LatitudeSeconds);
         Assert.AreEqual(0, location.Altitude);
         Assert.AreNotEqual(location, new Location());
         Assert.AreNotSame(location, new Location());
      }

      [TestMethod]
      public void TestMoveNorth()
      {
         Location location = new Location();
         location.Move(4000.0f, 0);
         Assert.AreEqual(0, location.Longitude);
         Assert.AreEqual(0, location.LongitudeTotalMinutes);
         Assert.AreEqual(Hemisphere.East, location.LongitudeHemisphere);
         Assert.AreEqual(0, location.LongitudeDegrees);
         Assert.AreEqual(0, location.LongitudeMinutes);
         Assert.AreEqual(0, location.LongitudeSeconds);
         Assert.AreEqual(4000, location.Latitude);
         Assert.AreEqual(66, location.LatitudeTotalMinutes);
         Assert.AreEqual(Hemisphere.North, location.LatitudeHemisphere);
         Assert.AreEqual(1, location.LatitudeDegrees);
         Assert.AreEqual(6, location.LatitudeMinutes);
         Assert.AreEqual(40, location.LatitudeSeconds);
         Assert.AreEqual(0, location.Altitude);
         Assert.AreNotEqual(location, new Location());
         Assert.AreNotSame(location, new Location());
      }

      [TestMethod]
      public void TestMoveSouth()
      {
         Location location = new Location();
         location.Move(-4000.0f, 0);
         Assert.AreEqual(0, location.Longitude);
         Assert.AreEqual(0, location.LongitudeTotalMinutes);
         Assert.AreEqual(Hemisphere.East, location.LongitudeHemisphere);
         Assert.AreEqual(0, location.LongitudeDegrees);
         Assert.AreEqual(0, location.LongitudeMinutes);
         Assert.AreEqual(0, location.LongitudeSeconds);
         Assert.AreEqual(-4000, location.Latitude);
         Assert.AreEqual(-66, location.LatitudeTotalMinutes);
         Assert.AreEqual(Hemisphere.South, location.LatitudeHemisphere);
         Assert.AreEqual(1, location.LatitudeDegrees);
         Assert.AreEqual(6, location.LatitudeMinutes);
         Assert.AreEqual(40, location.LatitudeSeconds);
         Assert.AreEqual(0, location.Altitude);
         Assert.AreNotEqual(location, new Location());
         Assert.AreNotSame(location, new Location());
      }

      [TestMethod]
      public void TestCollection()
      {
         Dictionary<ILocation, int> store = new Dictionary<ILocation, int>();
         ILocation location = new Location();
         location.Altitude = 1234;
         location.LongitudeHemisphere = Hemisphere.West;
         location.LongitudeDegrees = 147;
         location.LongitudeMinutes = 47;
         location.LongitudeSeconds = 7;
         location.LatitudeHemisphere = Hemisphere.South;
         location.LatitudeDegrees = 47;
         location.LatitudeMinutes = 7;
         location.LatitudeSeconds = 0.6f;
         store.Add(location, 314159);

         Assert.AreEqual(1, store.Count);
         Assert.IsTrue(store.ContainsKey(location));
         Assert.IsTrue(store.ContainsKey(new Location().CopyFrom(location)));
         Assert.IsFalse(store.ContainsKey(new Location().CopyFrom(location).Move(0, 0, 1)));
         Assert.IsFalse(store.ContainsKey(new Location().CopyFrom(location).Move(0, 1, 0)));
         Assert.IsFalse(store.ContainsKey(new Location().CopyFrom(location).Move(1, 0, 0)));
         Assert.AreEqual(314159, store[location]);
      }
   }
}
